package edu.xmut.kakamusic.utils;

import android.content.Context;
import android.content.SharedPreferences;

public class SPUtils {
    private static final String TAG = "SPUtils";
    private static final String SP_NAME = "user";
    private final SharedPreferences preferences;
    private final SharedPreferences.Editor editor;

    public SPUtils(Context context) {
        preferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        editor = preferences.edit();
    }

    public void putString(String key, String value) {
        editor.putString(key, value);
        editor.commit();
    }

    public String getString(String key) {
        return preferences.getString(key, "");
    }

    public void putInt(String key, int value) {
        editor.putInt(key, value);
        editor.commit();
    }

    public int getInt(String key, int defaultValue) {
        return preferences.getInt(key, defaultValue);
    }

    public void putBoolean(String key, boolean value) {
        editor.putBoolean(key, value);
        editor.commit();
    }

    public boolean getBoolean(String key, boolean defaultValue) {
        return preferences.getBoolean(key, defaultValue);
    }

    public void remove(String key) {
        editor.remove(key);
        editor.commit();
    }

    public void clear() {
        editor.clear();
        editor.commit();
    }
}
